package by.bsuir.service;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import by.bsuir.entity.Node;

public class NodeServiceImpl implements NodeService {

    public void save(Node node) {
        ObjectOutputStream out;
        try {
            out = new ObjectOutputStream(new FileOutputStream("node.dat"));
            out.writeObject(node);
            out.close();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    public Node read(Long id) {
        ObjectInputStream in;
        Node node = null;
        try {
            in = new ObjectInputStream(new FileInputStream("node.dat"));
            node = (Node) in.readObject();
            in.close();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return node;
    }

}
